﻿//hightlight text
function hightlightText(id) {
    document.getElementById(id).focus();
    document.getElementById(id).select();
}

// make default text of textbox
function makeDefaultText() {

    //address textbox
    $(".tb1").focus(function (srcc) {
        $(this).removeClass("defaultTextActive");
        if ($(this).val() == $(this)[0].title) {
            $(this).val("");
        }
    });

    $(".tb1").blur(function () {
        if ($(this).val() == "") {
            $(this).addClass("defaultTextActive");
            $(this).val($(this)[0].title);
        }
    });

    $(".tb1").blur();

    //start point textbox
    $(".tb2").focus(function (srcc) {
        $(this).removeClass("defaultTextActive");
        if ($(this).val() == $(this)[0].title) {            
            $(this).val("");
        }
    });

    $(".tb2").blur(function () {
        if ($(this).val() == "") {
            $(this).addClass("defaultTextActive");
            $(this).val($(this)[0].title);
        }
    });

    $(".tb2").blur();

    //end point textbox
    $(".tb3").focus(function (srcc) {
        $(this).removeClass("defaultTextActive");
        if ($(this).val() == $(this)[0].title) {
            $(this).val("");
        }
    });

    $(".tb3").blur(function () {
        if ($(this).val() == "") {
            $(this).addClass("defaultTextActive");
            $(this).val($(this)[0].title);
        }
    });

    $(".tb3").blur();
}

//make autocomplete feature for textbox
function makeAutocomplete(cityId) {
    $.getJSON("city/getPlaces/" + cityId, function (places) {
        //address textbox
        $("#txtAddress").unautocomplete();
        $("#txtAddress").autocomplete(places, {
            minChars: 0,
            max: 4,
            width: 521,
            autoFill: false,
            matchContains: "word",
            formatItem: function (row, i, max) {
                return row.title;
            },
            formatMatch: function (row, i, max) {
                return row.title;
            },
            formatResult: function (row) {
                return row.title;
            }
        });

        //start location textbox
        $("#start_location").unautocomplete();
        $("#start_location").autocomplete(places, {
            minChars: 0,
            max: 4,
            width: 253,
            matchContains: "word",
            autoFill: false,
            formatItem: function (row, i, max) {
                return row.title;
            },
            formatMatch: function (row, i, max) {
                return row.title;
            },
            formatResult: function (row) {
                return row.title;
            }
        });

        //end location textbox
        $("#end_location").unautocomplete();
        $("#end_location").autocomplete(places, {
            minChars: 0,
            max: 4,
            width: 253,
            matchContains: "word",
            autoFill: false,
            formatItem: function (row, i, max) {
                return row.title;
            },
            formatMatch: function (row, i, max) {
                return row.title;
            },
            formatResult: function (row) {
                return row.title;
            }
        });

        makeDefaultText();
    });

}

//change tab (tab menu)
function changeTab(activeTab) {
    var set = $('#navmenu').html();
    $("a", set).removeClass("selected").filter("[href='" + activeTab + "']", set).addClass("selected");
    $.each($("a", set), function (key, value) {
        $($(value).attr("href")).hide();
    });
    $(activeTab).show();
    $(".qtip").remove();
}

//make draggable div
$(function () {
    $("#draggable").draggable({ containment: "parent", scroll: false });
});


//make scroolable div
function mCustomScrollbars_1() {
    $("#mcs1_container").mCustomScrollbar("vertical", 0, "easeOutCirc", 1.05, "auto", "yes", "no", 0);
}

//make scroolable div
function mCustomScrollbars_2() {
    $("#mcs2_container").mCustomScrollbar("vertical", 0, "easeOutCirc", 1.05, "auto", "yes", "no", 0);
}

//close search box
function closeSearchBox() {
    document.getElementById('draggable').style.visibility = "hidden";
    document.getElementById('restoreTab').style.visibility = "visible";
}

//open search box
function openSearchBox() {
    document.getElementById('draggable').style.visibility = "visible";
    document.getElementById('restoreTab').style.visibility = "hidden";
}

//hide search box
function hideSearchBox() {
    document.getElementById('draggable').style.visibility = "hidden";
}

//close search box
function showSearchBox() {
    document.getElementById('draggable').style.visibility = "visible";
}

//open fancy box
function openFancybox() {
    $.fancybox({
        'autoScale': true,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'href': '#inline1',
        'titleShow': false,
        'padding': 0,
        'scrolling': 'no'
    });
}

//create qtip
function createQtip(element, tipContent, width, xpos, ypos) {
    
    $(".qtip").remove();
    if (typeof $(element).data("qtip") === "object")
        $(element).qtip('destroy');

    $(element).qtip({
        content: tipContent,
        style: {
            width: width,
            padding: 5,
            background: '#C4C4C4',
            color: 'black',
            textAlign: 'left',
            border: {
                width: 3,
                radius: 5,
                color: '#C4C4C4'
            },
            tip: 'topLeft',
            name: 'light' // Inherit the rest of the attributes from the preset dark style
        },
        show: {
            ready: false, /* Don't show the tooltip once its ready */
            when: false, /*  Prevents the tooltip from showing for any event */
            delay: 4000
        },
        position: {
            adjust: {
                x: xpos,
                y: ypos
            }
        }
    });
    $(element).qtip('show');
}

//cut string
function cutString(text) {
    var tem = text;
    if (text.length > 50) {
        tem = tem.substring(0, 45);
        tem += " ...";
    }
    return tem;
}